<template>
  <el-dialog v-model="dialogInfo.visible" :title="dialogInfo.title" :width="dialogInfo.width" align-center>
    <div class="app_card pt-4  pb-5">
      <el-table stripe size="large" :data="dataOfTable" height="calc(100vh - 400px)">
        <el-table-column label="任务ID" prop="taskName" align="center">
         <template #default="scope">{{ scope.row.taskId }}</template>
        </el-table-column>
        <el-table-column label="任务指令" prop="value" align="center">
         <template #default="scope">{{
            scope.row.value == 0 ? "全关" : "全开"
          }}</template>
        </el-table-column>

        <el-table-column label="任务时间" prop="floor" align="center" show-overflow-tooltip>
         <template #default="scope">{{scope.row.createdTime}}</template>
        </el-table-column>

      </el-table>
      <div class="mt-2">
        <el-pagination background v-model:currentPage="queryParam.page" v-model:page-size="queryParam.pageSize" :page-sizes="paginationOption.pageSizes" :background="false" :layout="paginationOption.layout" :total="paginationOption.total" @size-change="handleChangeSize" @current-change="handleChangeCurrent" />
      </div>
    </div>
  </el-dialog>
</template>

<script setup>

import { ref } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import EsAjax from '@/utils/EsAjax';
import ApiUrls from '@/apis/index';

// ======================================================
//                      变量声明
// ======================================================

// emit
const emit = defineEmits(['success']);
// 弹窗信息
const dialogInfo = ref({
  visible: false,
  title: '',
  width: '800px',
})

// 表格数据
const dataOfTable = ref([]);
// 表格查询参数
const queryParam = ref({
  q: '',
  search: '',
  orderby: '',
  group_id: 0,
  page: 1,
  pageSize: 10,
})
// 分页栏配置数据
const paginationOption = ref({
  layout: 'total, sizes, prev, pager, next, jumper',
  pageSizes: [10, 20, 50, 100, 500, 1000],
  total: 0,
})

// ======================================================
//                      点击操作
// ======================================================


// 点击取消按钮
const onCancel = () => {
  dialogInfo.value.visible = false;
}

// ======================================================
//                      处理事件
// ======================================================


// 加载数据
const show = (id, title, item = null, width = '600px') => {
  console.log(id, title, item, width)
  dialogInfo.value.title = title;
  dialogInfo.value.width = width;
  dialogInfo.value.visible = true;
  if (id) {
    queryParam.value.taskId = id
    loadData()
  }
}

const loadData = (id) => {
  EsAjax.post(ApiUrls.tasklogList, queryParam.value).then(res => {
    if (res.data.code !== 200) {
      ElMessage.warning(res.data.msg);
      return;
    }
    console.error(res)
    dataOfTable.value = res.data.data.data;
    paginationOption.value.total = res.data.data.total;
  }).catch(err => {
    ElMessage.error(err.message);
  })
}



defineExpose({
  show
})
</script>
